//#include"Camera.h"
//#include"Detection.h"
//#include"Pose.h"
//int main()
//{
////for quit
//int key=0;
////Camera object to capture frames from the webcam
//Camera Video1;
//CvPoint* Red;
//CvPoint* Green;
//Pose pose;
//IplImage* InitFrame=0,*NextFrame=0;
//CvPoint* Center=new CvPoint[3];
////CvMemStorage* storage = cvCreateMemStorage(0);
////	// Note that you must copy C:\Program Files\OpenCV\data\haarcascades\haarcascade_frontalface_alt2.xml
////	// to your working directory
////	CvHaarClassifierCascade* cascade = (CvHaarClassifierCascade*)cvLoad( "haarcascade_frontalface_alt2.xml" );
////	double scale = 1.3;
////
////	static CvScalar colors[] = { {{0,0,255}}, {{0,128,255}}, {{0,255,255}}, 
////	{{0,255,0}}, {{255,128,0}}, {{255,255,0}}, {{255,0,0}}, {{255,0,255}} };
////
////	// Detect objects
////	cvClearMemStorage( storage );
////
////while(key!='q'){
////InitFrame=cvLoadImage("pose1.bmp");
////cvShowImage("Show",InitFrame);
////
////Detection Detect(InitFrame);
////Detect.DetectRed();
////Center=Detect.Segmentation(Detect.GetResult());
//////Segment=Detect.GetSegment();
////for(int i=0;i<3;i++)
////{
////	cvCircle(Detect.GetResult(),Center[i],20,cvScalar(250,250,0,50),3);
////}
////Red=Detect.RedPosition();
////cvCircle(Detect.GetResult(),*Red,20,cvScalar(250,250,0,250),3);
////pose.SetRWrist(Red);
////Detect.DetectGreen();
////Green=Detect.GreenPosition();
////cvCircle(Detect.GetResult(),*Green,20,cvScalar(250,250,250,250),6);
////cvShowImage("Result",Detect.GetResult());
////key=cvWaitKey(1);
////pose.SetLWrist(Green);
////}
//while(key!='q')
//{
//////return the image and save it
//NextFrame=Video1.GetFrame();
//Video1.SaveFrame();
////display current frame
////NextFrame=cvLoadImage("pic.jpg");
//cvShowImage("Show",NextFrame);
//////CvSeq* objects = cvHaarDetectObjects( frame, cascade, storage, 1.1, 4, 0, cvSize( 40, 50 ));
//////
//////	CvRect* r;



//////	// Loop through objects and draw boxes
//////	for( int i = 0; i < (objects ? objects->total : 0 ); i++ ){
//////		r = ( CvRect* )cvGetSeqElem( objects, i );
//////		cvRectangle( frame, cvPoint( r->x, r->y ), cvPoint( r->x + r->width, r->y + r->height ),
//////			colors[i%8]);}
//////	cvShowImage("Show",frame);
////
//////Detection object to detect the colors in the frame
//Detection Detect(NextFrame);
////detect the red colors
//Detect.DetectRed();
////Get the red marker center
////Detect.Segmentation(Detect.GetResult());
//Center=Detect.Segmentation(Detect.GetResult());
////Segment=Detect.GetSegment();
//for(int i=0;i<3;i++)
//{
//	cvCircle(Detect.GetResult(),Center[i],20,cvScalar(250,250,0,50),3);
//}
////Red=Detect.RedPosition();
//////detect the green color
////Detect.DetectGreen();
//////Get the Green marker Center
////Green=Detect.RedPosition();
//////save image after detection
//////cvSaveImage("result.jpg",Detect.GetResult());
//////Draw circle
////cvCircle(Detect.GetResult(),*Red,20,cvScalar(250,0,0,250),3);
////show image after detection
//cvShowImage("Result",Detect.GetResult());
///* wait 10ms to process the next frame and exit if user press 'q' */
//key = cvWaitKey(1);
//}
//Video1.~Camera();
//return 0;
//}


#include"Camera.h"
#include"Detection.h"
int main()
{
//for quit
int key=0;
//Camera object to capture frames from the webcam
Camera Video1;
IplImage* frame=0;
CvPoint*Center=new CvPoint[3];

while(key!='q')
{
//return the image and save it
frame=Video1.GetFrame();
//Video1.SaveFrame();
//display current frame
cvShowImage("Show",frame);
//Detection object to detect the colors in the frame
Detection Detect(frame);
//detect the red colors
Detect.DetectRed();
vector<CvPoint> RedPoints=Detect.GetPoints();
if(RedPoints.size()!=0)
{

//Get the segmentation
Center=Detect.Segmentation(Detect.GetResult());

//for(int i=0;i<3;i++)
//{
//	cvCircle(Detect.GetResult(),Center[i],20,cvScalar(250,250,0,50),3);
//}
}
//detect the green color
//Detect.DetectGreen();

//save image after detection
//cvSaveImage("result.jpg",Detect.GetResult());
//show image after detection
cvShowImage("Result",Detect.GetResult());
/* wait 10ms to process the next frame and exit if user press 'q' */
key = cvWaitKey(1);
}
Video1.~Camera();
return 0;
}
